package com.ant.storage.controller;


import com.ant.storage.common.ResultVo;
import com.ant.storage.pojo.CapitalAccount;
import com.ant.storage.service.ICapitalAccountService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author melon
 * @since 2023-11-17
 */
@RestController
@RequestMapping("/capitalAccount")
public class CapitalAccountController {

    @Autowired
    private ICapitalAccountService capitalAccountService;

    @ApiOperation(value = "获取报销类型")
    @GetMapping("/findCostType")
    public ResultVo findCostType() {
        return ResultVo.success("操作成功", capitalAccountService.costTypeLists());
    }


    @ApiOperation(value = "保存")
    @PostMapping("/save")
    public ResultVo save(@RequestBody CapitalAccount account) {
        if (account.getId() == null) {
            capitalAccountService.save(account);
        } else {
            capitalAccountService.updateById(account);
        }
        return ResultVo.success("操作成功");
    }


    @ApiOperation(value = "获取报销类型")
    @GetMapping("/findCostTypeById/{id}")
    public ResultVo findCostTypeById(@PathVariable("id") Integer id) {
        if (id == null) {
            return ResultVo.success("操作失败功");
        }
        return ResultVo.success("操作成功", capitalAccountService.list(new QueryWrapper<CapitalAccount>()
                .eq("parent_id", id)));
    }


    @ApiOperation(value = "获取报销类型")
    @GetMapping("/findCostTypes")
    public ResultVo findCostTypes() {
        return ResultVo.success("操作成功", capitalAccountService.list(new QueryWrapper<CapitalAccount>()
                .eq("account_key", 1)));
    }
}
